/*
 *   A task scheduler that implements Monte-Carlo simulation
 *
 *   Copyright (C) 2011 Systasis Computer Systems, Inc.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   $Id: AboutView.java 101 2011-08-22 17:17:51Z jchimene@gmail.com $
 */
package com.systasis.sked.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.LazyPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.systasis.sked.client.presenter.AboutPresenter;
import com.systasis.sked.client.resources.Resources;
import com.systasis.sked.client.resources.SkedConstants;
import com.systasis.sked.client.resources.SkedStrings;

public class AboutView extends LazyPanel implements AboutPresenter.MyView {

    private DialogBox about;
    final private SkedConstants CONSTANTS = GWT.create(SkedConstants.class);
    final private Resources RESOURCES = GWT.create(Resources.class);
    final private SkedStrings STRINGS = GWT.create(SkedStrings.class);

    @Override
    public void addToSlot(Object slot, Widget content) {
    }

    @Override
    public Widget asWidget() {
	return about;
    }

    @Override
    public void removeFromSlot(Object slot, Widget content) {
    }

    @Override
    public void setInSlot(Object slot, Widget content) {
    }

    @Override
    public void showAbout() {
	ensureWidget();
	about.show();
    }

    @Override
    protected Widget createWidget() {
	final VerticalPanel contents = new VerticalPanel();
	final Button ok = new Button(STRINGS.closeButtonText());
	about = new DialogBox();
	about.setGlassEnabled(true);

	ok.addClickHandler(new ClickHandler() {
	    @Override
	    public void onClick(ClickEvent event) {
		about.hide();
	    }
	});

	about.setHTML(STRINGS.aboutCaption());

	contents.add(new HTML("<div style='padding: 5pt; font: medium/14pt caption'>" //
		+ STRINGS.titlePackage() //
		+ CONSTANTS.aboutLeading() //
		+ CONSTANTS.aboutCopyright() //
		+ CONSTANTS.aboutLeading() //
		+ CONSTANTS.aboutCopyrightJsgantt() //
		+ CONSTANTS.aboutLeading() //
		+ CONSTANTS.aboutCopyrightGwtGantt() //
		+ CONSTANTS.aboutLeading() //
		+ STRINGS.aboutBuiltUsing() //
		+ GWT.getVersion() + ")" //
		+ CONSTANTS.aboutLeading() //
		+ STRINGS.aboutVersion() //
		+ CONSTANTS.nbsp() //
		+ RESOURCES.getVersion().getText() //
		+ "</div>"));
	contents.add(ok);
	about.setWidget(contents);
	return about;
    }
}
